/***
 * 网络唤醒（Wake-on-LAN，WOL）
 *  是一种计算机局域网唤醒技术
 * Created by lihao on 2023-10-09 17:46:52
 */

let express = require('express');
let router = express.Router();
const WOL_TOOLS = require('./wol')
const Request = require("request");

/***
 * 测试服务器加密
 */
router.get('/start', (req, res) => {
    // dell pc : AC:ED:5C:47:CC:CD
    const DEVICE_MAC = req.body.mac || req.query.mac || 'AC:ED:5C:47:CC:CD'
    WOL_TOOLS.wakeOnLAN(DEVICE_MAC, {}).then(
        wol_res => {
            console.log(wol_res);
            res.send({ code: 0, msg: JSON.stringify(wol_res) });
        },
        err => {
            res.send({ code: -1, msg: err.message });
            console.log('wol', err.message);
        }
    );
})

router.get('/ip', (req, res) => {
    Request({
        url: 'http://docs.cdbytech.top:3000/updateIp',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({ ip: '110.184.201.5' })
    }, (error, response, body) => {
        if (!error && response.statusCode === 200) {
            // console.log('api请求结果: ', body, req.method) // 请求成功的处理逻辑
            res.send(body);
        } else {
            console.log('_error', error)
            res.send({ code: -1 });
        }
    })
})

module.exports = router;
